<?php
/**
 *  extention.func.php 用户自定义函数库
 *
 * @copyright			(C) 2005-2010 PHPCMS
 * @license				http://www.phpcms.cn/license/
 * @lastmodify			2010-10-27
 */
 
 
function order_auto_done(){
	$order_db = pc_base::load_model('order_model');
	$sql1 = "UPDATE phpcms_order SET order_status='1' WHERE (order_status='0' OR order_status='2') AND timeshop+1800 < UNIX_TIMESTAMP('".date('Y-m-d H:i:s',SYS_TIME)."')";
	$sql = "UPDATE phpcms_order SET order_status='2' WHERE order_status='0' AND timeshop < UNIX_TIMESTAMP('".date('Y-m-d H:i:s',SYS_TIME)."')";
	$order_db->query($sql);
	$order_db->query($sql1);
}
 
 
function validateDate($date, $format = 'Y-m-d H:i:s')
{

	if (strtotime(date('Y-m-d H:i:s', $date)) == $date) {
		if(date('Y', $date)=='1970'){
			 return false;
		}else{
			$realdate = date('Y-m-d H:i:s', $date);
			$d = DateTime::createFromFormat($format, $realdate);
			return $d && $d->format($format) == $realdate;
		}
    } else {
        return false;
    }
}

/**
 * 格式化商品价格
 *
 * @access  public
 * @param   float   $price  商品价格
 * @return  string
 */
function price_format($price, $change_price = true)
{
    if($price==='')
    {
     $price=0;
    }
    if ($change_price && defined('ECS_ADMIN') === false)
    {
        switch ($GLOBALS['_CFG']['price_format'])
        {
            case 0:
                $price = number_format($price, 2, '.', '');
                break;
            case 1: // 保留不为 0 的尾数
                $price = preg_replace('/(.*)(\\.)([0-9]*?)0+$/', '\1\2\3', number_format($price, 2, '.', ''));

                if (substr($price, -1) == '.')
                {
                    $price = substr($price, 0, -1);
                }
                break;
            case 2: // 不四舍五入，保留1位
                $price = substr(number_format($price, 2, '.', ''), 0, -1);
                break;
            case 3: // 直接取整
                $price = intval($price);
                break;
            case 4: // 四舍五入，保留 1 位
                $price = number_format($price, 1, '.', '');
                break;
            case 5: // 先四舍五入，不保留小数
                $price = round($price);
                break;
        }
    }
    else
    {
        $price = number_format($price, 2, '.', '');
    }

    return $price;
}

function get_onlineip() {
    $socket = socket_create(AF_INET, SOCK_STREAM, 6);  
    $ret = socket_connect($socket,'ns1.dnspod.net',6666);  
    $buf = socket_read($socket, 16);  
    socket_close($socket);  
    return $buf;      
 }
 
 
 
 
function sendsms($phone,$str){
		//$result = file_get_contents('http://sms.mobset.com/SDK/Sms_Send.asp?CorpID=113635&LoginName=jxt&Passwd=792949&send_no='.$phone.'&msg='.iconv('UTF-8', 'GB2312', $str));
		//echo 'http://service.winic.org/sys_port/gateway/?id=cbxboy&pwd=cbx8869725&to='.$phone.'&content='.urlencode($str).'&time=';
 		$result = file_get_contents('http://service.winic.org/sys_port/gateway/?id=cbxboy&pwd=cbx8869725&to='.$phone.'&content='.urlencode(iconv('UTF-8', 'GB2312', $str)).'&time=');
		//echo $result;
		$resultarr =explode('/',$result);
		//exit;
		if ($resultarr[0] ==000){
			return 1;
		}else{
			return $result;
		} 
}
 
 
 
 
?>